home *** CD-ROM | disk | FTP | other *** search
- Path: news.spb.su!demos!usenet
- From: Alexey Ruzin <00alex@demos.su>
- Newsgroups: comp.lang.c++
- Subject: Re: Constructor and enum Question...
- Date: Tue, 16 Apr 1996 21:02:58 +0400
- Organization: Demos Online Service
- Message-ID: <3173D2C2.4D68@demos.su>
- References: <4kujav$892@news.nde.state.ne.us>
- NNTP-Posting-Host: 00alex@dbs.demos.su
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; SunOS 5.4 sun4m)
-
- cwu wrote:
- >
- > Recently I am studying C++ and have a difficulty to understand
- > "constructor" and "enum". I am very appreciated any comments.
-
- Hi, excuse me for my Engilsh.
-
- As for 'enum':
-
- In short, it looks like set of defines, which declare 'int' constants.
- These defines are grouped in type, but you don't need use it mnemonic
- names always. Example:
-
- ...
- enum {a,b,c} f;
- ...
-
- this is equal:
-
- ...
- #define a 0
- #define b 1
- #define c 2
- int f; /* f may be 0,1,2; Hmm... i never tried to initialize with
- another values... It's interesting... ??? */
- ...
-
- Of course, if it was no difference between 'enum' and 'defines' there
- would no 'enums' and 'defines' together. But at the beginning of
- undestanding you may believe it.
-
- As for 'constructor':
-
- Again in short, It is function first called when object is initialized.
- In practice it is function is served to DO THIS JOB (initialization).
- Imagine a child, each child has a child and he knows her
- with birth. Lets make two classes 'Child' & 'Mother':
-
- class Mother
- {
- ...
- };
-
- class Child
- {
- Mother mom;
- ...
- public:
- Child( Mother the_mom ) { mom = the_mom; }
- };
-
- ...
-
- main()
- {
- ...
- Mother a_mother;
- Child a_child( a_mother );
- ...
- }
-
- As we see, each child at moment of birth is initialized with value
- of his monther. Who does this work -> 'constructor'. Another way
- call some functions after birth to say what is mother of a child,
- but constructor works perfectly. In addition, there are some
- cases where no way to misuse (don't use) constructor (when
- you use references: int &a=b; :this is one way to initialize variable
- -> use constructor).
-
- I hope it helps... Good luck.
-
- to
-